﻿
using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
using UnityEngine;

public class GroupBaseData : MonoBehaviour
{
    #region GroupInspectorUI

    #region hit result config
    [FoldoutGroup("通用设置"), LabelText("动作组编号")]
    //动作组编号
    public int GroupNum = 0;

    [FoldoutGroup("通用设置"), LabelText("角色的ID号")]
    //角色的ID号
    public int Race = 0;

    [MultiLineProperty(3)]
    [FoldoutGroup("通用设置"), LabelText("描述")]
    public String Desc = "";

    [Space(20)]
    [FoldoutGroup("通用设置"), LabelText("默认动作等级,单位的默认动作等级，用来进行霸体判断\n，每个动作可以重载动作等级。默认值为10")]
    //单位的默认动作等级，用来进行霸体判断，每个动作可以重载动作等级。默认值为10
    public int DefaultActionLevel = 10;

    [FoldoutGroup("通用设置"), LabelText("起始动作(城镇)")]
    //该单位(在城镇里面)创建出来时候的默认动作
    public String StartupAction = "N0000";

    [FoldoutGroup("通用设置"), LabelText("起始动作(副本)")]
    //该单位(在副本里面)创建出来时候的默认动作
    public String StartupActionInstance = "N0000";

    [Space(20)]
    [FoldoutGroup("通用设置", false), LabelText("能否被抓取/受击结果")]
    public bool CanCapture;

    [FoldoutGroup("通用设置")]
    public bool HasCollision = false;

    [FoldoutGroup("通用设置")]
    public bool RotateOnHit = true;

    [FoldoutGroup("通用设置")]
    public bool CheckDeath = false;

    //TODO
    //[FoldoutGroup("AI设置", false)]
    //public AISetting AISetting = new AISetting();

    [Space(20)]
    [FoldoutGroup("通用设置", false), LabelText("角色包围盒(调整模型下Collider大小然后点刷新保存数据)")]
    public Vector3 BoundBox;
    [FoldoutGroup("通用设置", false), LabelText("角色包围盒偏移值")]
    public Vector3 BoundBoxOffset;

    [FoldoutGroup("通用设置", false), Button("刷新包围盒")]
    public void RefreshBox()
    {
       //刷新自己包围盒,并保存数据
       var selfBoxArr =  CameraModelCtr.Ins.RefrshSelfBox();
       BoundBox = selfBoxArr[0];
       BoundBoxOffset = selfBoxArr[1];
    }

    [FoldoutGroup("通用设置", false), LabelText("冲击减免,当怪物受到攻击时，冲击速度减免量，默认为不减免(1 1 1)")]
    //当怪物受到攻击时，冲击速度减免量，默认为不减免(1 1 1)
    public Vector3 LashModifier = new Vector3(1, 1, 1);

    [FoldoutGroup("通用设置")]
    //重力加速度
    public Int32 Gravtity = 1000;
    #endregion

    #region dead
    [FoldoutGroup("死亡动作", false), LabelText("站立死亡动作")]
    public String StandDeath = "H1040";

    [FoldoutGroup("死亡动作", false), LabelText("倒地死亡动作")]
    public String DownDeath = "H1041";

    #endregion

    #region hit result on ground

    [FoldoutGroup("受击结果:地面", false), LabelText("受到倒地追击攻击时")]
    //受到倒地追击攻击时的动作ID号
    public String FloorDownHit = "H0070";

    [FoldoutGroup("受击结果:地面"), LabelText("受到倒地攻击时")]
    //受到倒地攻击时的动作ID号
    public String FloorFallDown = "H0031";

    [FoldoutGroup("受击结果:地面"), LabelText("受到浮空攻击时")]
    //受到浮空攻击时的动作ID号
    public String FloorDiagUp = "H0030";

    [FoldoutGroup("受击结果:地面"), LabelText("受到浮空追击攻击时")]
    //受到浮空追击攻击时的动作ID号
    public String FloorAirHit = "H0070";

    [FoldoutGroup("受击结果:地面"), LabelText("受到击倒攻击时")]
    //受到击倒攻击时的动作ID号
    public String FloorKnockDown = "H0070";

    [FoldoutGroup("受击结果:地面"), LabelText("受到击飞攻击时")]
    //受到击飞攻击时的动作ID号
    public String FloorKnockOut = "H0010";

    [FoldoutGroup("受击结果:地面"), LabelText("受到击退攻击时")]
    //受到击退攻击时的动作ID号
    public String FloorKnockBack = "H0070";

    [FoldoutGroup("受击结果:地面"), LabelText("站立受击时")]
    //站立受击时的动作ID号
    public String FloorStandHit = "H0070";

    [FoldoutGroup("受击结果:地面"), LabelText("抓住攻击时")]
    //受到抓住攻击时的动作ID号
    public String FloorHold = "H0050";

    #endregion

    #region hit result in area

    [FoldoutGroup("受击结果:空中", false), LabelText("受到倒地追击攻击时的动作")]
    //受到倒地追击攻击时的动作ID号
    public String AirDownHit = "H0060";

    [FoldoutGroup("受击结果:空中"), LabelText("受到倒地攻击时的动作")]
    //受到倒地攻击时的动作ID号
    public String AirFallDown = "H0031";

    [FoldoutGroup("受击结果:空中"), LabelText("受到浮空攻击时动作")]
    //受到浮空攻击时的动作ID号
    public String AirDiagUp = "H0030";

    [FoldoutGroup("受击结果:空中"), LabelText("受到浮空追击攻击时动作")]
    //受到浮空追击攻击时的动作ID号
    public String AirAirHit = "H0060";

    [FoldoutGroup("受击结果:空中"), LabelText("受到击倒攻击时动作")]
    //受到击倒攻击时的动作ID号
    public String AirKnockDown = "H0040";

    [FoldoutGroup("受击结果:空中"), LabelText("搜道击飞时动作")]
    //受到击飞攻击时的动作ID号
    public String AirKnockOut = "H0010";

    [FoldoutGroup("受击结果:空中"), LabelText("受到击退攻击时动作")]
    //受到击退攻击时的动作ID号
    public String AirKnockBack = "H0010";

    [FoldoutGroup("受击结果:空中"), LabelText("站立受击时动作")]
    //站立受击时的动作ID号
    public String AirStandHit = "H0060";

    [FoldoutGroup("受击结果:空中"), LabelText("受到抓住攻击时动作")]
    //受到抓住攻击时的动作ID号
    public String AirHold = "H0050";

    #endregion

    #region hit result in stand

    [FoldoutGroup("受击结果:站立", false), LabelText("受到倒地追击时动作")]
    //受到倒地追击攻击时的动作ID号
    public String StandDownHit = "H0070";

    [FoldoutGroup("受击结果:站立"), LabelText("受到倒地攻击时动作")]
    //受到倒地攻击时的动作ID号
    public String StandFallDown = "H0031";

    [FoldoutGroup("受击结果:站立"), LabelText("受到浮空攻击时动作")]
    //受到浮空攻击时的动作ID号
    public String StandDiagUp = "H0030";

    [FoldoutGroup("受击结果:站立"), LabelText("受到浮空追击时动作")]
    //受到浮空追击攻击时的动作ID号
    public String StandAirHit = "H0060";

    [FoldoutGroup("受击结果:站立"), LabelText("受到击倒攻击时")]
    //受到击倒攻击时的动作ID号
    public String StandKnockDown = "H0040";

    [FoldoutGroup("受击结果:站立"), LabelText("受到击飞攻击时动作")]
    //受到击飞攻击时的动作ID号
    public String StandKnockOut = "H0010";

    [FoldoutGroup("受击结果:站立"), LabelText("受到击退攻击时动作")]
    //受到击退攻击时的动作ID号
    public String StandKnockBack = "H0020";

    [FoldoutGroup("受击结果:站立"), LabelText("站立受击动作")]
    //站立受击时的动作ID号
    public String StandStandHit = "H0000";

    [FoldoutGroup("受击结果:站立"), LabelText("被抓动作")]
    //受到抓住攻击时的动作ID号
    public String StandHold = "H0050";

    #endregion

    #endregion
    [OdinInspectorButton]
    public GroupBaseData groupInspectorData;
    private void OnEnable()
    {
        groupInspectorData = this;
    }
    private Data.ActionGroup data;
    public void SetData(Data.ActionGroup group)
    {
        this.data = group;

        BoundBox.x = data.BoundingLength;
        BoundBox.y = data.BoundingWidth;
        BoundBox.z = data.BoundingHeight;
        BoundBoxOffset.x = data.BoundingLengthOffset;
        BoundBoxOffset.y = data.BoundingWidthOffset;
        BoundBoxOffset.z = data.BoundingHeightOffset;

        CanCapture = data.CanCapture;

        #region death
        StandDeath = data.StandDeath;
        DownDeath = data.DownDeath;
        #endregion

        //TODO AI

        #region other
        LashModifier = new Vector3(data.LashModifier.X, data.LashModifier.Y, data.LashModifier.Z);
        GroupNum = data.GroupNum;
        Race = data.Race;

        DefaultActionLevel =data.DefaultActionLevel ;
        StartupAction = data.StartupAction;
        StartupActionInstance = data.StartupActionInstance;
        HasCollision  = data.HasCollision ;
        RotateOnHit = data.RotateOnHit;
        Desc = data.Desc;
        CheckDeath = data.CheckDeath ;
        #endregion

        data.Gravtity = Gravtity;

        #region hit result on ground
        FloorDownHit = data.FloorDownHit;
        FloorFallDown = data.FloorFallDown;
        FloorDiagUp = data.FloorDiagUp;
        FloorAirHit = data.FloorAirHit;
        FloorKnockDown = data.FloorKnockDown;
        FloorKnockOut = data.FloorKnockOut;
        FloorKnockBack = data.FloorKnockBack;
        FloorStandHit = data.FloorStandHit;
        FloorHold = data.FloorHold;
        #endregion

        #region hit result in area
        AirDownHit = data.AirDownHit;
        AirFallDown = data.AirFallDown;
        AirDiagUp = data.AirDiagUp;
        AirAirHit = data.AirAirHit;
        AirKnockDown = data.AirKnockDown;
        AirKnockOut = data.AirKnockOut;
        AirKnockBack = data.AirKnockBack;
        AirStandHit = data.AirStandHit;
        AirHold = data.AirHold;
        #endregion

        #region hit result in stand
        StandDownHit = data.StandDownHit;
        StandFallDown = data.StandFallDown;
        StandDiagUp = data.StandDiagUp;
        StandAirHit = data.StandAirHit;
        StandKnockDown = data.StandKnockDown;
        StandKnockOut = data.StandKnockOut;
        StandKnockBack = data.StandKnockBack;
        StandStandHit = data.StandStandHit;
        StandHold = data.StandHold;
        #endregion

        //刷新自己包围盒
        CameraModelCtr.Ins.RefreshSelfBox();
    }
    public void SaveData()
    {
        data.BoundingLength =(int) (BoundBox.x);
        data.BoundingHeight = (int)(BoundBox.y);
        data.BoundingWidth = (int)(BoundBox.z);

        data.BoundingLengthOffset = (int)BoundBoxOffset.x;
        data.BoundingHeightOffset = (int)BoundBoxOffset.y;
        data.BoundingWidthOffset = (int)BoundBoxOffset.z;
        
        data.CanCapture = CanCapture;

        #region death
        data.StandDeath = StandDeath;
        data.DownDeath = DownDeath;
        #endregion

        //TODO AI

        #region other
        data.LashModifier = new Data.Vector3(LashModifier.x,LashModifier.y,LashModifier.z);
        data.GroupNum = GroupNum;
        data.Race = Race;
        data.DefaultActionLevel = DefaultActionLevel;
        data.StartupAction = StartupAction;
        data.StartupActionInstance = StartupActionInstance;
        data.HasCollision = HasCollision;
        data.RotateOnHit = RotateOnHit;
        data.Desc = Desc;
        data.CheckDeath = CheckDeath;
        #endregion

        data.Gravtity = Gravtity;

        #region hit result on ground
        data.FloorDownHit = FloorDownHit;
        data.FloorFallDown = FloorFallDown;
        data.FloorDiagUp = FloorDiagUp;
        data.FloorAirHit = FloorAirHit;
        data.FloorKnockDown = FloorKnockDown;
        data.FloorKnockOut = FloorKnockOut;
        data.FloorKnockBack = FloorKnockBack;
        data.FloorStandHit = FloorStandHit;
        data.FloorHold = FloorHold;
        #endregion

        #region hit result in area
        data.AirDownHit = AirDownHit;
        data.AirFallDown = AirFallDown;
        data.AirDiagUp = AirDiagUp;
        data.AirAirHit = AirAirHit;
        data.AirKnockDown = AirKnockDown;
        data.AirKnockOut = AirKnockOut;
        data.AirKnockBack = AirKnockBack;
        data.AirStandHit = AirStandHit;
        data.AirHold = AirHold;
        #endregion

        #region hit result in stand
        data.StandDownHit = StandDownHit;
        data.StandFallDown = StandFallDown;
        data.StandDiagUp = StandDiagUp;
        data.StandAirHit = StandAirHit;
        data.StandKnockDown = StandKnockDown;
        data.StandKnockOut = StandKnockOut;
        data.StandKnockBack = StandKnockBack;
        data.StandStandHit = StandStandHit;
        data.StandHold = StandHold;
        #endregion
        //刷新自己包围盒
        CameraModelCtr.Ins.RefreshSelfBox();
        EventManager.TriggerEvent<Data.ActionGroup>(CommonEvent.RefreshCurActionGroup, data);
    }

    
}
